<template>
<div class="user">
    <el-form size="small" ref="form" :model="form" label-width="150px">
      <!--添加门店-->
      <div class="common-form">{{$t('plus.flash_sale_settings')}}</div>
      <el-form-item
        :label="$t('plus.unpaid_orders')"
        prop="orderClose"
        :rules="[{  required: true,  message: ' '}]"
      >
        <div style="width: 500px">
          <el-input
            :placeholder="$t('plus.please_input')"
            v-model="form.orderClose"
            type="number"
          >
            <template #append> {{$t('plus.close_after_minutes')}} </template>
          </el-input>
          <p class="gray"> {{$t('plus.flash_sale_timeout_note')}} 

</p>
        </div>
      </el-form-item>
      <!--      <el-form-item label="是否开启优惠券抵扣" prop="isCoupon">
        <el-switch v-model="form.isCoupon"></el-switch>
      </el-form-item> -->
      <el-form-item :label="$t('plus.enable_distribution1')" prop="isAgent">
        <el-switch v-model="form.isAgent"></el-switch>
        <!-- <p>注：如需使用分销功能必须在 [分销中心 - 分销设置] 中开启</p> -->
      </el-form-item>
      <el-form-item :label="$t('plus.enable_point_deduction')" prop="isPoint"
        ><el-switch v-model="form.isPoint"></el-switch
      ></el-form-item>
    </el-form>

    <!--提交-->
    <div class="common-button-wrapper">
      <el-button
        size="small"
        type="primary"
        @click="onSubmit"
        :disabled="loading"
        >{{$t('plus.save')}}</el-button
      >
    </div>
  </div>
</template>

<script>
import SeckillApi from "@/api/seckill.js";
export default {
  data() {
    return {
      form: {
        orderClose: 10,
        isCoupon: false,
        isAgent: false,
        isPoint: false
      },
      setting: [],
      loading: false
    };
  },
  created() {
    /*获取列表*/
    this.getSetting();
  },
  methods: {
    /*获取设置*/
    getSetting() {
      let self = this;
      let Params = {};
      SeckillApi.getSetting(Params, true).then(res => {
        self.loading = false;
        self.form = res.data;
      }).catch(error => {});
    },
    /*点击保存*/
    onSubmit() {
      let self = this;
      let params = self.form;
      if (!(params.orderClose > -1) || !params.orderClose) {
        ElMessage({
          message: $t("plus.unpaid_order_error"),
          type: "error"
        });
        return false;
      }
      self.loading = true;
      SeckillApi.saveSetting(params, true).then(data => {
        self.loading = false;
        if (data.code == 1) {
          ElMessage({
            message: $t("plus.save_success"),
            type: "success"
          });
          self.getSetting();
        } else {
          self.loading = false;
        }
      }).catch(error => {
        self.loading = false;
      });
    }
  }
};
</script>

